import QtQuick 2.0

Rectangle {
    property int value: 0
    property int min: -10
    property int max: 100000
    property int step: 1
    width: 200
    height: 25
    color: "black"
    opacity: 0.5
    radius: 4

    onValueChanged: input.text = value

    function setValue(v) {
        var newVal = v
        if (newVal < min)
            newVal = min
        if (newVal > max)
            newVal = max
        value = newVal
        input.text = value
    }

    TextInput {
        id: input
        anchors.verticalCenter: parent.verticalCenter
        width: parent.width - plusButton.width * 2
        x: 5
        color: "white"
        //text: value
        font.family: "Orbitron"; font.pointSize: 10
        selectByMouse: true
        selectionColor: "gray"
        selectedTextColor: "black"
        validator: IntValidator { bottom: min; top: max }
        onTextChanged: setValue(text)
    }

    ToolButton {
        anchors.right: plusButton.left
        icon: "img/arrow_up.png"
        onClicked: {
            setValue(value + step)
        }
    }
    ToolButton {
        id: plusButton
        anchors.right: parent.right
        icon: "img/arrow_down.png"
        onClicked: {
            setValue(value - step)
        }
    }
}
